<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>人员组列表——人员管理系统</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="shortcut icon" href="images/title.jpg">
		<link type="text/css" rel="stylesheet" href="css/main.css"charset="UTF-8" />
		<link rel="stylesheet" href="layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="css/global.css" media="all">
		<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">
		<link rel="stylesheet" href="datatables/media/css/jquery.dataTables.css">
		<link rel="stylesheet" href="datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css">
		<link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.15/css/jquery.dataTables.css">
		<link rel="stylesheet" href="css/bootstrap.css" />
		<link rel="stylesheet" href="css/bootstrap.min.css" />
		<!--<style>
			.layui-table {
				text-align: center;
			}
			
			ul.layui-nav:nth-child(1) {
				margin-left: 0px;
			}
			
			#layer1 {
				
				background-color: #009688;
			}
			#groupTable thead th{
			    border-bottom: 0px white;
			}
			table.dataTable{
				border-collapse:collapse;
			}
			.layui-layout-admin .header-demo {
			  background-color: #009688;
			}
			.layui-btn {
    
    background-color: #99cc33;
    
}
.layui-btn-warm {
    background-color: #0099cc;
}

		</style>-->

	</head>

	<body onload="redata()">
		<div class="layui-layout layui-layout-admin" style="border-bottom: solid 5px #FFFFFF;">
			<!--头部导航-->
			<div class="layui-header header header-demo"></div>
			<!--左侧导航-->
			<div class="layui-side layui-bg-black" id="admin-side"></div>
			<!--右侧具体内容-->

			<div class="layui-body" style="bottom: 0;border-left: solid 2px #FFFFFF;padding:20px" id="admin-body">
				<div>
					<div class="title" style="float: left;">人员组管理</div>
					<button data-method="offset" data-type="auto" class="layui-btn layui-btn-normal" id="layer1" style="float: right;" >新建调查小组</button>
				</div>
				<hr/ style="border-color: #858585;">
				<div style="padding: 20px; background-color: #F2F2F2;">
  					<div class="layui-row layui-col-space15">
						<div class="layui-col-md12">
      						<div class="layui-card">
        						<div class="layui-card-body">
									<div class="layui-form" id="stlist">
										<table class="layui-table" id="groupTable" style="border-bottom:0px white;">
											<thead >
												<tr>
													<th style="width: 500px;text-align: center;">小组名称</th>
													<th style="text-align: center;">操作1</th>
													<th style="text-align: center;">操作2</th>
													<th style="text-align: center;">操作3</th>
												</tr>
											</thead>
											<tbody id="tbodysh">
											</tbody>
											<footer></footer>
										</table>
									</div>
								</div>
      						</div>
    					</div>
  					</div>
    			</div>
			</div>
		</div>
		<!--JS模块-->

		<script type="text/javascript" src="layui/layui.js"></script>
		<script src="js/jquery-1.12.3.min.js"></script>
		<script src="js/index.js"></script>
		<script type="text/javascript" src="js/jquery.cookie.js"></script>
		<script type="text/javascript" src="js/dateRange.js"></script>
		<script type="text/javascript" charset="utf8" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
		<script type="text/javascript" charset="utf8" src="http://cdn.datatables.net/1.10.15/js/jquery.dataTables.js"></script>
		<script type="text/javascript" src="js/bootstrap.min.js"></script>
		
		<script type="text/javascript">
			var configJson='config.json'
			/*$.getJSON(configJson,function(data){
				ip=data.urlip;
			})*/
			var ip="http://qure.zjgsu.edu.cn";
		var content="";
		var id=0;
		
		function redata() {
			$.ajax({
				type: "get",
				url:ip+"/surveyGroup",
				data: {
				},
				xhrFields: {
						withCredentials: true
						},
				crossDomain: true,
				async: true,
				dataType: "json",
				
				success: function(res) {
					content=res.data;
					adddata(content);
				},
			});
		}
	
		 
 
 


		//新增按钮
		$(document).on('click','#layer1',function(){
			layer.open({
				type:1,
				title: '请输入小组名称',
				skin: 'layui-layer-rim', //加上边框
  				area: ['300px', '200px'], //宽高
				content: '<input type="text" id="newgroupname" name="groupname"style="height:30px;margin-top: 35px;margin-left: 30px;"><input type="button" value="确定"id="addsearchgroup"class="layui-btn layui-btn-sm" style="margin-left:70%;width:20%;height:20%">',
			
			});
		})
		//编辑按钮
		$(document).on('click','.edit',function(){
			layer.open({
				type:1,
				title: '编辑小组名称',
				skin: 'layui-layer-rim', //加上边框
  				area: ['300px', '200px'], //宽高
				content: '<input type="text" id="editname" name="groupname"style="height:30px;margin-top: 35px;margin-left: 30px;"><input type="button" value="确定"id="editsearchgroup"class="layui-btn layui-btn-sm" style="margin-left:70%;width:20%;height:20%">',
			
			});
			id=this.id;
		})
		
		//新增
		$(document).on('click',"#addsearchgroup",function(){
			var name=$('#newgroupname').val();
			$.ajax({
				type: "post",
				url:ip+"/surveyGroup/add",
				data:JSON.stringify({
  					"groupName":name,
  					}),
  					xhrFields: {
						withCredentials: true
						},
				crossDomain: true,
				async: true,
				dataType: "json",
				contentType: "application/json",
				success: function(res) {
					if(res.code==0){
					
					 redata();
					 layer.msg("新增成功！");
					}
					if(res.code==-1){
						layer.msg(res.msg);
						
					}
					
				},
				
			});
			
        layer.closeAll('page');
		})
		
		//编辑
		$(document).on('click',"#editsearchgroup",function(){
			var name=$('#editname').val();
			$.ajax({
				type: "put",
				url:ip+"/surveyGroup/updateSurveyGroup",
				data:JSON.stringify({
				    "surveyGroupId":id,
  					"surveyGroupName":name
  					
  					}),
  					xhrFields: {
						withCredentials: true
						},
				crossDomain: true,
				async: true,
				dataType: "json",
				contentType: "application/json",
				success: function(res) {
					if(res.code==0){
					
					 redata();
					 layer.msg("编辑成功！");
					}
					if(res.code==-1){
						layer.msg(res.msg);
						
					}
					
				},
				
			});
			
        layer.closeAll('page');
		})
		
		
		//填充数据具体步骤
		function adddata(note) {
			var before="<tr id='group";
			var after="</tr>";
			var between="";
			var content="";
			for(var i=0;i<note.length;i++)
			{
				var j=i+1;
				between="<td>"+note[i].groupName+"</td>";
				between=before+j+"'>"+between+"<td><a href='eachteam.html?id=" + note[i].id + "&name="+note[i].groupName+"'><button class='layui-btn layui-btn-danger  layui-btn-small check' id='check"+j+"'>   查看   </button></a> </td>"+"<td><button class='layui-btn layui-btn-warm  layui-btn-small edit' id="+note[i].id+">编辑</button></td>"+"<td><button class='layui-btn layui-btn-warm  layui-btn-small delete' id='delete"+j+"'>删除</button></td>"+after;
				content=content+between;
			}
			$("#tbodysh").html(content);
		}
		function addnewdata(name,j)
		{
			var before="<tr id='group";
			var after="</tr>"
			var between="";
			between="<td>"+name+"</td>";
			between=before+j+"'>"+between+"<td><a href='eachteam.html?id=" +id + "&name="+name+"'><button class='layui-btn layui-btn-danger  layui-btn-small check' id='check"+j+"'>查看</button></a></td>"+"<td><button class='layui-btn layui-btn-warm  layui-btn-small edit'  id="+note[i].id+">编辑</button></td>"+"<td><button class='layui-btn layui-btn-warm  layui-btn-small delete' id='delete"+j+"'>删除</button></td>"+after;
			return between;
		}
		
		//删除按钮
		 $(document).on('click', '.delete', function() {
		 	k = $(this).parents("tr").index() + 1;
		 	var number=this.id;
		 	number=number.replace(/[^0-9]/ig,"");
		 	console.log(number);
		 	layui.use('layer', function() {
		 		var layer = layui.layer;
		 		layer.confirm('是否要删除该调查小组', {
		 			btn: ['确定', '取消'],
		 			icon: 2,
		 			title: '提示',
		 			btn1:function(index, layero){
		 				$.ajax({
		 				type: "delete",
		 				url: ip + "/surveyGroup/" +content[number-1].id,
		 				data: {},
		 				xhrFields: {
						withCredentials: true
						},
				crossDomain: true,
		 				async: true,
		 				dataType: "json",
		 				contentType: "application/json",
		 				success: function(data) {
		 					if(data.code==0){
		 					$("table#groupTable").find("tr:eq(" + k + ")").remove();
		 					}
		 					if(data.code==-1)
		 					{
		 						layer.msg(data.msg)
		 					}
							layer.close(index);
		 				},
		 				Error: function() {
		 					alert("服务器出错");
		 				}
		 			})
		 				
		 		}
		 			
		 	})
		
		});
	})
		 
	function isLogin(){
				$.ajax({
					 				type: "get",
					 				url:ip+"/user/type ",
					 				data: {},
					 				async: true,
					 				dataType: "",
					 				
					 				xhrFields: {
									withCredentials: true
									},
									crossDomain: true,
					 				success: function(res) {
					 					if(res.code==-1){
					 						layui.use('layer', function(){
			  									var layer = layui.layer;
			  									layer.msg(res.msg);
											});     
					 						
					 						window.location.href="login.html";
					 						console.log(res.msg);
					 					}
									
					 				},
					 				Error: function() {
					 					alert("服务器出错");
					 				}
					 			})
}	  
 
$(function() {
					isLogin();
					
			});

			  $('#groupTable').DataTable({
                    responsive: true,
                    ordering: false,
                    searching:false,
                    "bLengthChange": false,
                    "bRetrieve": true,
                    "bFilter": false, //过滤功能
                    "info": false,  
                    "paging": false,   
                    language: {
       					"sProcessing": "处理中...",
       					"sLengthMenu": "显示 _MENU_ 项结果",
       					"sZeroRecords": "没有匹配结果",
       					"sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
       					"sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
       					"sInfoFiltered": "(由 _MAX_ 项结果过滤)",
       					"sInfoPostFix": "",
       					"sSearch": "搜索:",
       					"sUrl": "",
       					"sEmptyTable": "表中数据为空",
      					"sLoadingRecords": "载入中...",
       					"sInfoThousands": ",",
				       "oPaginate": {
				           "sFirst": "首页",
				           "sPrevious": "上页",
				           "sNext": "下页",
				           "sLast": "末页"
				       },
				       "oAria": {
				           "sSortAscending": ": 以升序排列此列",
				           "sSortDescending": ": 以降序排列此列"
				       }
  				 }
                });
		</script>

	</body>

</html>